package jgl.vajra.driver.part.mine.activity;

import android.content.Intent;

import java.util.List;

import jgl.vajra.driver.R;
import jgl.vajra.driver.databinding.ActivityPersonalInformationBinding;
import jgl.vajra.driver.manager.IntentManager;
import jgl.vajra.driver.part.mine.contract.PersonalInformationContract;
import jgl.vajra.driver.part.mine.viewModel.PersonalInformationViewModel;
import jgl.vajra.driver.widget.bean.ProfileFileBean;
import jgl.vajra.driver.widget.giide.GlideImageLoader;
import jgl.vajra.driver.widget.interfaces.ImagePickerListener;
import jgl.vajra.driver.widget.interfaces.UploadListener;
import jgl.vajra.driver.widget.manager.UploadFileManager;
import jgl.vajra.driver.widget.mvvm.factory.CreateViewModel;
import jgl.vajra.driver.widget.mvvm.view.BaseMVVMActivity;
import jgl.vajra.driver.widget.utils.PickFileToolsV2;

@CreateViewModel(PersonalInformationViewModel.class)
public class PersonalInformationActivity extends BaseMVVMActivity<PersonalInformationViewModel, ActivityPersonalInformationBinding> implements PersonalInformationContract.View {

    private PickFileToolsV2 pickFileTools;
    private String avatarUrl;

    @Override
    public int getLayoutId() {
        return R.layout.activity_personal_information;
    }

    @Override
    public void initView() {
        super.initView();
        mBinding.setView(this);
    }

    //头像
    @Override
    public void onHeadPortrait() {
        if (pickFileTools == null)
            pickFileTools = PickFileToolsV2.init(this);
        pickFileTools.pick(true, 0, new ImagePickerListener() {
            @Override
            public void onPickImageList(List<String> imgs, int tag) {
                super.onPickImageList(imgs, tag);
                UploadFileManager.getInstance().uploadPath(imgs.get(0), "", new UploadListener() {
                    @Override
                    public void onUploadSuccess(List<ProfileFileBean> file) {

                    }

                    @Override
                    public void onUploadStringSuccess(List<String> file) {
                        avatarUrl = file.get(0);
                        GlideImageLoader.onAvatarDisplayRound(mBinding.ivAvatar, avatarUrl, null);
                    }

                    @Override
                    public void onUploadFailed() {

                    }
                });
            }
        });
    }

    //江湖名号
    @Override
    public void onName() {
        IntentManager.toNicknamePageActivity(this);
    }

    //实名认证
    @Override
    public void onNameAuthentication() {
            IntentManager.toNameAuthenticationActivity(this);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (pickFileTools != null) {
            pickFileTools.onActivityResult(requestCode, resultCode, data);
        }
    }
}
